<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="奖金清算" prop="bonusSettlement.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择奖金清算"
            labelName = 'totalBonus'
            labelValue = 'id'
            :value = "inputForm.bonusSettlement.id"
            :limit="1"
            @getValue='(value) => {inputForm.bonusSettlement.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'totalBonus',
              label: '奖金总额'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'totalBonus',
              label: '奖金总额'
            }
            ]"
            dataListUrl="/epc/bonussettlement/bonusSettlement/list"
            entityBeanName="bonusSettlement"
            queryEntityUrl="/epc/bonussettlement/bonusSettlement/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName"
                :rules="[
                  {required: true, message:'项目名称不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.projectName" placeholder="请填写项目名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="可清算奖金" prop="liquidableBonus"
                :rules="[
                 ]">
              <el-input v-model="inputForm.liquidableBonus" placeholder="请填写可清算奖金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="已清算奖金" prop="endLiquidableBonus"
                :rules="[
                 ]">
              <el-input v-model="inputForm.endLiquidableBonus" placeholder="请填写已清算奖金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目借款" prop="projectLoan"
                :rules="[
                 ]">
              <el-input v-model="inputForm.projectLoan" placeholder="请填写项目借款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="个人借款" prop="personalLoan"
                :rules="[
                 ]">
              <el-input v-model="inputForm.personalLoan" placeholder="请填写个人借款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="凭证编号" prop="proofNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.proofNumber" placeholder="请填写凭证编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="凭证摘要" prop="certificatePaper"
                :rules="[
                 ]">
              <el-input v-model="inputForm.certificatePaper" placeholder="请填写凭证摘要"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否过账" prop="isPost"
                :rules="[
                 ]">
                <el-select v-model="inputForm.isPost" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否作废" prop="isCancellation"
                :rules="[
                 ]">
                <el-select v-model="inputForm.isCancellation" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="数据重采" prop="dataMining"
                :rules="[
                 ]">
                <el-select v-model="inputForm.dataMining" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="制单日期" prop="documentationDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.documentationDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="附单据数" prop="attachedDocuments"
                :rules="[
                 ]">
              <el-input v-model="inputForm.attachedDocuments" placeholder="请填写附单据数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="会计姓名" prop="accountantName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.accountantName" placeholder="请填写会计姓名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          bonusSettlement: {
            id: ''
          },
          projectName: '',
          liquidableBonus: '',
          endLiquidableBonus: '',
          projectLoan: '',
          personalLoan: '',
          proofNumber: '',
          certificatePaper: '',
          isPost: '',
          isCancellation: '',
          dataMining: '',
          documentationDate: '',
          attachedDocuments: '',
          accountantName: '',
          remarks: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建奖金清算明细`
        } else if (method === 'edit') {
          this.title = '修改奖金清算明细'
        } else if (method === 'view') {
          this.title = '查看奖金清算明细'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/bonussettlementdetail/bonusSettlementDetail/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.bonusSettlementDetail)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/bonussettlementdetail/bonusSettlementDetail/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>